<%@page import="com.mbbcpa.standalone.engine.SecurityDetailModel"%>
<%@page import="com.mbbcpa.standalone.engine.FacilityDetailModel"%>
<%@page import="com.mbbcpa.standalone.engine.CpModel"%>
<%@page import="com.mbbcpa.util.StringUtils"%>
<%@ page import = "java.io.*" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.text.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.util.HashMap" %>

<%@page import="com.mbbcpa.reference.RefListModel"%>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.Vector" %>
<%@ page import="com.mbbcpa.app.manager.*" %>
<%@ page import="com.mbbcpa.app.EncryptionHelper" %>
<%@ page import="com.mbbcpa.app.EbppKeys" %>
<%@ page import="com.mbbcpa.util.*" %>
<%@ page import = "com.mbbcpa.security.dao.*" %>
<%@ page import = "com.mbbcpa.app.dao.*" %>
<%

// -- Loading Constants
	
	Map map = null;
	Vector vLosRefList = null;
	Vector vCountryRefList = null;
	Vector vFinTypeRefList = null;
	Vector vBorrowerDetails = null;
	Vector vFacilityDetails = null;
	LoanInfoDao loanInfoDao = null;
	Boolean isNew = true;
	
	//dataCount
	int borrowerCount = 0;
	int facilityCount = 0;
	int loanSecurityCount = 0;
	
	
	String countryCode = "";
	String losSrc = "";
	String finType = "";
	String aaNo = "";
	
// 	map.put("oMsgHeader",getReq_ESB_MsgHdr(doc));
// 	map.put("oLoanHeader",getLoanHeader(doc));
// 	map.put("oLoanInfo", getLoanInfo(doc));
// 	map.put("vFacility", getFacilityInfo(doc));
// 	map.put("vBorrower", getBorrowerInfo(doc));
// 	map.put("vCpList",getCpList(doc));
	
	
	map = (Map) request.getAttribute("map"); 
	loanInfoDao = (LoanInfoDao) map.get("oLoanInfo");
	
	vLosRefList = (Vector) map.get("vLosRefList");
	vCountryRefList = (Vector) map.get("vCountryRefList");
	vFinTypeRefList = (Vector) map.get("vFinTypeRefList");
	Vector vCPList = (Vector)  map.get("vCpList");
	vFacilityDetails = (Vector)  map.get("vFacility");
	
	String sResult = "";
		System.out.println("ManualCPResult.jsp vCPList.size()="+vCPList.size());
	if (vCPList.size()>0){
		CpModel oCpModel = (CpModel) vCPList.elementAt(0);	
		if(oCpModel.get_STF_PF_NO().trim().length() >0){
			System.out.println("ManualCPResult.jsp vCPList.size() is CP?"+vCPList.size());
			sResult = "Account is CP";		
		}else{
			sResult = "Account is Not CP";	
		}
	}else{
		sResult = "Account is Not CP";	
	}
	
	
	//check manualcp is newly loaded through the loanInfoDao
	if (loanInfoDao != null){
		
		isNew = false;
		
		// Loan Info
		countryCode = loanInfoDao.getCountryCode();
		losSrc = loanInfoDao.getLOSSrc();
		finType = loanInfoDao.getEntity();
		aaNo = loanInfoDao.getAANo();
		
		// Borrower Details
		vBorrowerDetails = (Vector) map.get("vBorrower");
		if (vBorrowerDetails != null){
			borrowerCount = vBorrowerDetails.size();
		}
	}
		
	
// -- Navigation

	// Get Manual CP Acces List
	ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
	
	// Get Login Details 
	SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
	String sUserName = oSecUserDao.getUserName();
	String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);
	
	// Module Declaration
	int iMan001 = 0;
	int iMan002 = 0;
	
	for(int i=0;i<secGroupAccessList.size();i++){
		SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
		String strModuleCode  = secaccessDao.getModuleCode();
	
		if(strModuleCode.equals("MAN001"))
			iMan001 = 1;
		if(strModuleCode.equals("MAN002"))
			iMan002 = 1;
	}

%>

<html>
<head>
<link rel="stylesheet" href="resource/mbb_sec_global.css" type="text/css" />
<link href="resource/style.css" rel="stylesheet" type="text/css">
</head>

<SCRIPT LANGUAGE="JavaScript1.2">


	window.history.forward();
	function checkInquiry() {
	
		window.history.forward(); 

	
	}
	
	
	function validateLoanInfo(){
		
		var isValid = false;
		var frm = document.frmManualCP;
		
		if (frm.countryCode.value == ""){
			alert("Please select a Country Code");
			frm.countryCode.focus();
		}else if (frm.finType.value == ""){
			alert("Please select an Entity");
			frm.finType.focus();		
		}else if(frm.losSrc.value == ""){ 
			alert("Please select a LOS Source");
			frm.losSrc.focus();	
		}else if(frm.aaNo.value == ""){
			alert("Please input AA No.");
			frm.aaNo.focus();		
		}
		else{
			isValid = true;
		}

		return isValid; 
	}
	
	
	function showBorrowerForm(){
		var frm = document.frmManualCP;
		//call validation function
		var isValid = validateLoanInfo();
		
		//alert (isValid);
			//validation success? put loan info in vector
			if (isValid == true){
				frm.action = "ManualCPInquiry.do?dispatch=addBorrowerDetails";
				frm.submit();
			}
	}
	
	
	function showFacilityForm(){
		var frm = document.frmManualCP;
		//call validation function
		var isValid = validateLoanInfo();
		
		//alert (isValid);
			//validation success? put loan info in vector
			if (isValid == true){
				frm.action = "ManualCPInquiry.do?dispatch=addFacilityInfo";
				frm.submit();
			}
	}
	
	
	function deleteData(index, table){
		var frm = document.frmManualCP;
		var msg = "Are you sure you want to delete this entry?";
		
		
		if (confirm(msg)){
			var frm = document.frmManualCP;
			frm.action = 'ManualCPInquiry.do?dispatch=deleteData&index=' + index + '&table=' + table;
			frm.submit();	
			//alert ("Delete element " + index + " from " + table );
		}
		
	}
	
	function editData(index, table){

		var frm = document.frmManualCP;
		var msg = "Are you sure you want to delete this entry?";
		
		frm.action = 'ManualCPInquiry.do?dispatch=editData&index=' + index + '&table=' + table;
		frm.submit();	

		
		
	}

	
	
	
	
</SCRIPT>
</head>


<body class="home" onpageshow="if (event.persisted) noBack();" onload="checkInquiry()" onunload="">

	<a name="top"></a>
	
<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->

<div id="bgWrapper">
		<div id="container">
		
					<div id="titleBar">
						<ul class="topBar">
							<li class="goBackBt"><a href="<%=request.getContextPath()%>/CheckUserLogon.do?dispatch=homePage"></a></li>
							<li>
							  <h1>CP Inquiry Result</h1></li>
						</ul>
					</div>
		
					<div id="fullcontent">
		
						<!-- Security Navigation -->
						<%@ include file="ManualCPNavigation.jsp" %>	
						<!-- End SecurityNavigation -->
			
			
						<div id="contentRightIn">
									
							<div id="moduleContainer">
							
							
									<!--  Module Title -->
									<table align="center" width=100% border="0" rules="cols" class="tblDetails">
										<thead>
											<tr>
												<th colspan="4">
													<h4>CP Inquiry  - <%=sResult%> </h4>
												</th>
											</tr>
										</thead>
									</table>


									<!-- Loan Info -->
													
										<table align="center" style="display:block;" class="tblDetails" width=100% border="0" rules="cols">
											<form name="frmManualCP" method="post">	
											
											<thead class="th1">
												<tr>
													<th colspan="4">
														<div class="frmTitle">
															<h2 class="manualCPFormTitle">Loans Info</h2>
														</div>
													</th>
												</tr>
											</thead>
												
											<tbody>
												 <tr class="even">
											        <td width="25%">Country Code:</td>
											        <td width="25%"><%=countryCode %></td>
											        <td width="25%">Entity:</td>
											        <td width="25%"><%=finType %></td>
											      </tr>
											      
											      <tr class="odd">
											        <td width="25%">LOS Source:</td>
											        <td width="25%"><%=losSrc%></td>
											        <td width="25%">AA NO. :</td>
											        <td width="25%"><%=aaNo%></td>
											        
											      </tr>  
											</tbody>
										</table>

									<!-- Facility Info Listing-->
										<table align="center" style="display:block;" class="tblDetails" width=100% border="0" rules="cols">
											<thead class="th1">
												<tr>
													<th colspan="9">
														<div class="frmTitle">
															<h2 class="manualCPFormTitle">Facility Info Listing</h2>
														</div>
													</th>
												</tr>
											</thead>
											
											<tbody>
												<!-- Detail Titles -->
											    <tr class="headerD" style="text-align:center !important;">
													<td width="5%" class="center_note">No.</td>
													<td width="15%" class="center_note">Facility ID</td>
													<td width="15%" class="center_note">Facility Type Code</td>
													<td width="15%" class="center_note">Product Type Code</td>
													<td width="15%" class="center_note">CP Status</td>
												</tr>  
												<!-- Detail Rows -->
											 	<%
															for(int j = 0; j < vFacilityDetails.size(); j++){
																FacilityDetailModel oFacModel = (FacilityDetailModel) vFacilityDetails.elementAt(j);	
																String rowclass = ((j % 2) == 0 ? "even":"odd");											
													%>
															<tr class="<%=rowclass%>" align="center">
																<td><%=j+1%></td>
																<td><%=oFacModel.get_Facility_ID()%></td>
																<td><%=oFacModel.get_Facility_Type_Code()%></td>
																<td><%=oFacModel.get_Product_Type_Code()%></td>
																<td><%=oFacModel.get_CP_Status()%></td>
															</tr>	
													<%
														Vector vSecurity = oFacModel.get_Security_Info();
														if (vSecurity.size()>0){
															%>
																<!-- Loan Security Listing -->
																<table align="center" style="display:block;" class="tblDetails" width=100% border="0" rules="cols">
																	<thead class="th1">
																		<tr>
																			<th colspan="5">
																				<div class="frmTitle">
																					<h2 class="manualCPFormTitle">Loan Security Listing</h2>
																				</div>
																			</th>
																		</tr>
																	</thead>
																	
																	<tbody>
																		<!-- Detail Titles -->
																	    <tr class="headerD" style="text-align:center !important;">
																			<td width="10%" class="center_note">No.</td>
																			<td width="20%" class="center_note">Security ID</td>
																			<td width="20%" class="center_note">Security Type</td>
																			<td width="20%" class="center_note">Security Value</td>
																			<td width="20%" class="center_note"></td>
																		</tr>  
																		<!-- Detail Rows -->
																		<%
															for(int k = 0; k < vSecurity.size(); k++){
																SecurityDetailModel oSecModel = (SecurityDetailModel) vSecurity.elementAt(k);	
																String rowclass1 = ((k % 2) == 0 ? "even":"odd");											
													%>
																<tr class="<%=rowclass1%>" >
																	<td><%=k+1%></td>
																	<td><%=oSecModel.get_Mbb_Security_ID()%></td>
																	<td><%=oSecModel.get_Mbb_Security_Type()%></td>
																	<td><%=oSecModel.get_Mbb_Security_Value()%></td>
																</tr>
														<%} %>
																	</tbody>
																</table>
															<%
														}
													
															}//for loop
													
													%>
												
												
											</tbody>
										</table>
<%
	System.out.println("ManualCPResult.jsp vBorrowerDetails.size()="+vBorrowerDetails.size());
%>
									<!-- Loan Borrower Listing -->
														
										<table align="center" style="display:block;" class="tblDetails" width=100% border="0" rules="cols">
											<thead class="th1">
												<tr>
													<th colspan="7">
														<div class="frmTitle">
															<h2 class="manualCPFormTitle">Loan Borrower Listing</h2>
														</div>
													</th>
												</tr>
											</thead>
											
											<tbody>
												<!-- Detail Titles -->
											    <tr class="headerD" style="text-align:center !important;">
													<td width="5%" class="center_note">No.</td>
													<td width="7%" class="center_note">GCIF No.</td>
													<td width="14%" class="center_note">Capacity</td>
													<td width="14%" class="center_note">ID</td>
													<td width="14%" class="center_note">Other ID</td>
													<td width="14%" class="center_note">CP Status</td>
													<td width="14%" class="center_note">CP Remarks</td>
												
												</tr>  
											
												
												<!-- Detail Rows -->
												
													<%
															for(int j = 0; j < vBorrowerDetails.size(); j++){
																BorrowerDetailsDao borrowerDetails = (BorrowerDetailsDao) vBorrowerDetails.elementAt(j);	
																String rowclass = ((j % 2) == 0 ? "even":"odd");											
													%>
															<tr class="<%=rowclass%>">
																<td><%=j+1%></td>
																<td><%=borrowerDetails.getGCIFNo()%></td>
																<td><%=borrowerDetails.getCapacity()%></td>
																<td>(<%=borrowerDetails.getIDType()%>)-<%=borrowerDetails.getIDNo()%></td>
																<td>(<%=borrowerDetails.getOtherIDType()%>)-<%=borrowerDetails.getOtherID()%></td>
																<td><%=borrowerDetails.get_CpStatus()%></td>
																<td><%=borrowerDetails.get_CpRemarks()%>																 
														</tr>	
													<%
															}//for loop
													
													%>
											</tbody>
										</table>
								<!-- CP List -->
														
										<table align="center" class="tblDetails" width=100% border="0" rules="cols" <%=vCPList.size()>0?"":"style=\"display:none\""%>>
											<thead class="th1">
												<tr>
													<th colspan="6">
														<div class="frmTitle">
															<h2 class="manualCPFormTitle">CP Info</h2>
														</div>
													</th>
												</tr>
											</thead>
											
											<tbody>
												<!-- Detail Titles -->
											    <tr class="headerD" style="text-align:center !important;">
													<td width="5%" class="center_note">No.</td>
													<td width="7%" class="center_note">Staff Name</td>
													<td width="14%" class="center_note">PF No.</td>
													<td width="14%" class="center_note">Designation</td>
													<td width="14%" class="center_note">Location</td>
													<td width="14%" class="center_note">Relationship</td>
												
												</tr>  
											
												
												<!-- Detail Rows -->
												
													<%
															for(int j = 0; j < vCPList.size(); j++){
																CpModel oCpModel = (CpModel) vCPList.elementAt(j);	
																String rowclass = ((j % 2) == 0 ? "even":"odd");											
													%>
															<tr class="<%=rowclass%>">
																<td><%=j+1%></td>
																<td><%=oCpModel.get_STF_NAME()%></td>
																<td><%=oCpModel.get_STF_PF_NO()%></td>
																<td><%=oCpModel.get_STF_DESIGNATION()%></td>
																<td><%=oCpModel.get_STF_PERSONAL_AREA()%></td>
																<td><%=oCpModel.get_SCP_CP_RELATIONSHIP()%></td>
															</tr>	
													<%
															}//for loop
													
													%>
											</tbody>
										</table>
										
										</form> <!-- end of frmManualCP -->	
						</div> <!--  moduleContainer END -->
							
					</div>
		
					<!-- Footer -->
					<%@ include file="/jsp/common/Footer.jsp" %>	
					<!-- End Footer -->
					</div>




</body>
</html>